<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
    <title>uTools多功能插件 | 响应式导航</title>
    <style>
        :root {
            --sidebar-width: 250px;
            --transition-duration: 0.3s;
            --header-height: 60px;
            --bg-color: #f5f7fa;
            --sidebar-bg: #ffffff;
            --primary-color: #2563eb;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: var(--bg-color);
            color: #333;
            height: 100vh;
            display: grid;
            grid-template-columns: var(--sidebar-width) 1fr;
            grid-template-rows: var(--header-height) 1fr;
            grid-template-areas: 
                "header header"
                "sidebar content";
            transition: grid-template-columns var(--transition-duration) ease;
            overflow: hidden;
        }
        
        /* 折叠状态 */
        .sidebar-collapsed {
            grid-template-columns: 0 1fr;
        }
        
        /* 响应式适配 */
        @media (max-width: 768px) {
            body {
                grid-template-columns: 0 1fr;
            }
            
            .sidebar-expanded {
                position: relative;
            }
            
            .sidebar-expanded::after {
                content: '';
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                background-color: rgba(0,0,0,0.3);
                z-index: 10;
            }
        }
        
        header {
            grid-area: header;
            background: var(--primary-color);
            color: white;
            padding: 0 1.5rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            z-index: 5;
        }
        
        .header-left {
            display: flex;
            align-items: center;
            gap: 1rem;
        }
        
        .app-logo {
            font-size: 1.8rem;
            display: flex;
            align-items: center;
        }
        
        .app-title {
            font-size: 1.3rem;
            font-weight: 600;
        }
        
        .header-controls {
            display: flex;
            gap: 0.8rem;
        }
        
        .header-btn {
            background: rgba(255,255,255,0.15);
            border: none;
            border-radius: 50%;
            width: 36px;
            height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.1rem;
            cursor: pointer;
            transition: all 0.2s;
        }
        
        .header-btn:hover {
            background: rgba(255,255,255,0.25);
            transform: scale(1.05);
        }
        
        aside {
            grid-area: sidebar;
            background-color: var(--sidebar-bg);
            display: flex;
            flex-direction: column;
            overflow: hidden;
            box-shadow: 2px 0 8px rgba(0,0,0,0.08);
            z-index: 20;
            transition: transform var(--transition-duration) ease;
        }
        
        .sidebar-content {
            padding: 1rem 0;
            flex: 1;
            overflow-y: auto;
        }
        
        .nav-list {
            list-style: none;
            padding: 0;
        }
        
        .nav-item {
            margin-bottom: 0.25rem;
        }
        
        .nav-link {
            display: flex;
            align-items: center;
            padding: 0.9rem 1.2rem;
            margin: 0 0.8rem;
            border-radius: 8px;
            text-decoration: none;
            color: #4a5568;
            transition: all 0.2s;
            overflow: hidden;
        }
        
        .nav-link:hover {
            background-color: #f3f4f6;
        }
        
        .nav-link.active {
            background-color: #ebf8ff;
            color: var(--primary-color);
            font-weight: 500;
        }
        
        .nav-icon {
            font-size: 1.3rem;
            min-width: 35px;
            text-align: center;
            margin-right: 0.8rem;
            transition: margin var(--transition-duration);
        }
        
        .nav-text {
            white-space: nowrap;
            font-size: 0.95rem;
            transition: opacity var(--transition-duration);
        }
        
        main {
            grid-area: content;
            padding: 1.5rem;
            overflow: hidden;
            transition: none;
        }
        
        iframe {
            width: 100%;
            height: 100%;
            border: none;
            border-radius: 10px;
            box-shadow: 0 2px 15px rgba(0,0,0,0.05);
            background: white;
        }
        
        .mobile-toggle-btn {
            display: none;
            position: fixed;
            bottom: 1.5rem;
            left: 1rem;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background: var(--primary-color);
            color: white;
            font-size: 1.5rem;
            z-index: 20;
            box-shadow: 0 4px 10px rgba(0,0,0,0.2);
            border: none;
            justify-content: center;
            align-items: center;
            cursor: pointer;
        }
        
        @media (max-width: 768px) {
            .mobile-toggle-btn {
                display: flex;
            }

            aside {
                position: fixed;        /* 固定定位 */
                top: var(--header-height);
                left: 0;
                width: 80%;
                max-width: 300px;
                height: calc(100% - var(--header-height));
                transform: none;        /* 关键：不再 transform */
                will-change: opacity;   /* 提示合成层 */
                opacity: 0;
                visibility: hidden;
                transition: opacity .3s ease, visibility .3s ease;
            }

            .sidebar-expanded aside {
                opacity: 1;
                visibility: visible;
            }

            /* 遮罩也做淡入淡出，防止生硬 */
            .sidebar-expanded::after {
                content: '';
                position: fixed;
                inset: 0;
                background: rgba(0,0,0,.3);
                z-index: 9;
                opacity: 0;
                visibility: hidden;
                transition: opacity .3s ease, visibility .3s ease;
            }
            .sidebar-expanded.sidebar-expanded::after {
                opacity: 1;
                visibility: visible;
            }
        }
    </style>
</head>
<body>
    <header>
        <div class="header-left">
            <div class="app-logo">🧰</div>
            <div class="app-title">uTools多功能插件</div>
        </div>
        <div class="header-controls">
            <button class="header-btn" title="刷新内容" onclick="refreshContent()">🔄</button>
            <button id="toggleSidebar" class="header-btn" title="切换侧边栏">📋</button>
        </div>
    </header>
    
    <aside>
        <div class="sidebar-content">
            <ul class="nav-list">
                <li class="nav-item">
                    <a href="#" data-url="刷题/index.html" class="nav-link active">
                        <span class="nav-icon">📚</span>
                        <span class="nav-text">PDF刷题系统</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" data-url="秒表/miaobiao/index.html" class="nav-link">
                        <span class="nav-icon">⏱️</span>
                        <span class="nav-text">秒表计时器</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" data-url="pdf功能合并/pages/tongji/index.html" class="nav-link">
                        <span class="nav-icon">📊</span>
                        <span class="nav-text">PDF打印分析</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" data-url="pdf功能合并/pages/chaifen/index.html" class="nav-link">
                        <span class="nav-icon">✂️</span>
                        <span class="nav-text">PDF页面拆分</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" data-url="pdf功能合并/pages/hebing/index.html" class="nav-link">
                        <span class="nav-icon">📑</span>
                        <span class="nav-text">PDF文档合并</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" data-url="pdf功能合并/pages/tupian/index.html" class="nav-link">
                        <span class="nav-icon">🖼️</span>
                        <span class="nav-text">PDF转图片</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" data-url="pdf功能合并/pages/tu2word/index.html" class="nav-link">
                        <span class="nav-icon">📃</span>
                        <span class="nav-text">图片插入Word</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" data-url="pdf功能合并/pages/pdf2word/index.html" class="nav-link active">
                        <span class="nav-icon">➡️</span>
                        <span class="nav-text">PDF转Word</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" data-url="kml合并/index.html" class="nav-link active">
                        <span class="nav-icon">🖇️</span>
                        <span class="nav-text">KML合并工具</span>
                    </a>
                </li>
            </ul>
        </div>
    </aside>
    
    <main>
        <iframe id="contentFrame" src="刷题/index.html"></iframe>
    </main>
    
    <button class="mobile-toggle-btn" id="mobileToggle">📋</button>
    
    <script>
        /* ========== 状态与元素 ========== */
        let isSidebarVisible = true;

        const body        = document.body;
        const contentFrame= document.getElementById('contentFrame');
        const toggleBtn   = document.getElementById('toggleSidebar');
        const mobileBtn   = document.getElementById('mobileToggle');
        const navLinks    = document.querySelectorAll('.nav-link');

        /* ========== 初始化 ========== */
        if (window.innerWidth < 768) {
            isSidebarVisible = false;
            // body.classList.add('sidebar-collapsed');   // ← 删掉
        } else {
            isSidebarVisible = true;
            body.classList.remove('sidebar-collapsed');
        }

        /* ========== 侧边栏开关 ========== */
        function toggleSidebar() {
            isSidebarVisible = !isSidebarVisible;

            if (isSidebarVisible) {
                body.classList.remove('sidebar-collapsed');
                body.classList.add('sidebar-expanded');

                /* 只绑定一次 */
            document.addEventListener('click', e => {
                if (!isSidebarVisible) return;
                const sidebar = document.querySelector('aside');
                if (!sidebar.contains(e.target) &&
                    !toggleBtn.contains(e.target) &&
                    !mobileBtn.contains(e.target)) {
                    toggleSidebar();
                }
            });
            } else {
                body.classList.remove('sidebar-expanded');
                body.classList.add('sidebar-collapsed');
                document.removeEventListener('click', closeOnOutsideClick);
            }
        }

        /* 移动端点击外部区域关闭 */


        /* ========== 页面加载 ========== */
        function loadPage(url) {
            contentFrame.src = url;
            navLinks.forEach(l => l.classList.remove('active'));
            this.classList.add('active');

            /* 移动端选完菜单后自动收起 */
            if (window.innerWidth < 768 && isSidebarVisible) {
                setTimeout(toggleSidebar, 300);
            }
        }

        /* ========== 刷新内容 ========== */
        function refreshContent() {
            contentFrame.contentWindow.location.reload();
        }

        /* ========== 事件绑定 ========== */
        toggleBtn.addEventListener('click', e => {
            e.stopPropagation();
            toggleSidebar();
        });

        mobileBtn.addEventListener('click', e => {
            e.stopPropagation();
            toggleSidebar();
        });

        navLinks.forEach(link => {
            link.addEventListener('click', function (e) {
                e.preventDefault();
                e.stopPropagation();
                loadPage.call(this, this.dataset.url);
            });
        });

        /* ========== 响应式适配 ========== */
        window.addEventListener('resize', () => {
            if (window.innerWidth > 768) {
                if (!isSidebarVisible) {
                    isSidebarVisible = true;
                    body.classList.remove('sidebar-collapsed');
                    body.classList.add('sidebar-expanded');
                }
                document.removeEventListener('click', closeOnOutsideClick);
            } else {
                if (!isSidebarVisible) {
                    body.classList.add('sidebar-collapsed');
                    body.classList.remove('sidebar-expanded');
                }
            }
        });
        
        /* 追加在现有 JS 末尾即可 */
        let edgeTimer;
        document.addEventListener('mousemove', e => {
        if (window.innerWidth < 768) return;        // 仅桌面生效
        if (e.clientX <= 5) {                      // 鼠标进入左边缘 5px
            clearTimeout(edgeTimer);
            if (!isSidebarVisible) toggleSidebar();
        } else if (isSidebarVisible && e.clientX > 250) {
            // 离开侧边栏区域 800ms 无返回则收起
            clearTimeout(edgeTimer);
            edgeTimer = setTimeout(toggleSidebar, 800);
        }
        });
    </script>
</body>
</html>